package cn.geminis.resources.service.model;

import cn.geminis.lowcode.annotation.*;
import com.vladmihalcea.hibernate.type.json.JsonType;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Allen
 */
@Getter
@Setter
@UuidEntity
@DynamicInsert
@DynamicUpdate
@QueryFilter
@CrudRepository
@CrudController(deleteInBatch = false)
public class User {

    @Column(nullable = false, length = 128)
    private String name;

    @Type(JsonType.class)
    @Column(columnDefinition = "json")
    private Object properties;

    @OneToMany(mappedBy = "user", cascade = {CascadeType.ALL})
    @QueryFilterProperty(fieldName = "organizations.organization.id", propertyName = "organizationId", propertyType = "String")
    private Set<OrgUser> organizations = new HashSet<>();

    @ManyToMany
    @OrderBy("showOrder")
    private Set<Role> roles = new HashSet<>();

}
